import { Pipe, PipeTransform } from '@angular/core';

import { HttpService } from '../../core/http/http.service';

@Pipe({
  name: 'bzFetchList'
})
export class FetchListPipe<U> implements PipeTransform {

  constructor(
    private httpService: HttpService<U>
  ) { }

  transform(url: U, args: any = {}): any {
    args._cache = true;
    const method = args._isPost ? 'post' : 'get';
    delete args._isPost;
    return this.httpService[method](url, args).then((res) => {
      return (res.data || []);
    });
  }

}
